import { localRouteRecordRaw } from '@/router/routes/types';

const localModules = import.meta.glob('./localModules/*.ts', { eager: true });
const externalModules = import.meta.glob('./externalModules/*.ts', {
  eager: true,
});
const permissionModules = import.meta.glob('./permissionModules/*.ts', {
  eager: true,
});
function formatModules(_modules: any, result: localRouteRecordRaw[]) {
  Object.keys(_modules).forEach((key) => {
    const defaultModule = _modules[key].default;
    if (!defaultModule) return;
    const moduleList = Array.isArray(defaultModule)
      ? [...defaultModule]
      : [defaultModule];
    result.push(...moduleList);
  });
  return result;
}

export const localRoutes: localRouteRecordRaw[] = formatModules(
  localModules,
  []
);
export const appExternalRoutes: localRouteRecordRaw[] = formatModules(
  externalModules,
  []
);
export const localPermissionRoutes: localRouteRecordRaw[] = formatModules(
  permissionModules,
  []
);
